﻿using System.Collections.Generic;
using System.Threading.Tasks;
using SmartCity.Shared;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace CommonManagement
{
    /// <summary>
    /// 服务应用服务类
    /// </summary>
    public class ServiceAppService : ApplicationService, IServiceAppService
    {
        private readonly IRepository<Service, int> _serviceRepository;

        public ServiceAppService(
            IRepository<Service, int> serviceRepository)
        {
            _serviceRepository = serviceRepository;
        }

        // 列表
        public async Task<ListResponse<ServiceDto>> ListAsync(string isRecommend = null)
        {
            // 查询
            var list = await _serviceRepository.ToListAsync();
            var count = list.Count;
            // 返回结果
            var dtos = ObjectMapper.Map<List<Service>, List<ServiceDto>>(list);
            return ListResponse<ServiceDto>.Successful(count, dtos);
        }
    }
}